library(FAIRsimulator) set.seed(32423)
This example will compare two parallel group designs. The first design, the basic design, has 100 subjects per treatment while the alternative design has 200 subjects per treatment arm.
This is a summary of the common features of the two designs:
StudyObjIni <- createStudy( nCohorts = 1, recruitmentAges = list(c(6,7)*30), nSubjects = c(500), cohortStartTimes = c(6*30), newCohortLink = list(NULL), Recruitmentfunction=function(...) {return(5000)}, samplingDesign = list(seq(0,12,by=2)*30), studyStopTime = 18*30+1, latestTimeForNewBirthCohorts=6*30, treatments =list(c("SoC-1","TRT-1","TRT-2","TRT-3","TRT-4")), effSizes = list(c(0.05,0.1,0.15,0.20,0.25)), randomizationProbabilities = list(rep(0.20,5)) )
The study is simulated with the AdaptiveStudy
function.
StudyObj <- AdaptiveStudy(StudyObjIni)
plotActiveSubjects(StudyObj)
The simulated HAZ values can be inspected using the plotHAZ
function.
plotHAZ(StudyObj)
plotHAZTreatmentEff(StudyObj)
The data can be used to update the posterior probability of the treatments to be better than the other treatments.
tmp <- getProbData(StudyObj,strProb = "UnWeightedUpdateProbabilities",cohortAgeNames="6-18 months") kable(tmp %>% select(TreatmentName,Prob))
TRT-3 is surprisingly the treatment with the highest probability of being the best treatment. However, this is based on a single realisation of the design. Running the study many times will allow us to compute statistics on the performance of the design.
The basic scenario is run 100 times to get statistics on the randomization probability updates.
iter <- 100 ncores <- 7 myMultStud <- runMultiSim(StudyObjIni,iter=iter,ncores=ncores)
Extract the probabilities of interest.
probDfUnweightedUpdate <- getMultiProbList(myMultStud[[1]],ncores=ncores, strProb="UnWeightedUpdateProbabilities", cohortAgeNames="6-18 months")
Summarise the end of treatment probabilities for plotting and tabulation.
sumData <- probDfUnweightedUpdate %>% filter(RandStudyTime == max(RandStudyTime)) %>% group_by(TreatmentName,CohortAge) %>% summarise( Mean=mean(Prob), Low=quantile(Prob,p=0.025), High=quantile(Prob,p=0.975) )
Plot and tabulate the treatment probability statistics.
ggplot(sumData,aes(TreatmentName,Mean,color=TreatmentName)) + geom_point() + geom_errorbar(aes(ymin=Low,ymax=High),width=0.2) + facet_wrap(~CohortAge,scales = "free_x")
kable(sumData %>% select(TreatmentName,Mean,Low,High) %>% rename(Treatment =TreatmentName,"P0.025"=Low,"P0.975"=High),dig=2)
set.seed(85859)
StudyObjIniAlt <- createStudy( nCohorts = 1, recruitmentAges = list(c(6,7)*30), nSubjects = c(1000), cohortStartTimes = c(6*30), newCohortLink = list(NULL), Recruitmentfunction=function(...) {return(5000)}, samplingDesign = list(seq(0,12,by=2)*30), studyStopTime = 18*30+1, latestTimeForNewBirthCohorts=6*30, treatments =list(c("SoC-1","TRT-1","TRT-2","TRT-3","TRT-4")), effSizes = list(c(0.05,0.1,0.15,0.20,0.25)), randomizationProbabilities = list(rep(0.20,5)) )
Execute the study.
StudyObjAlt <- AdaptiveStudy(StudyObjIniAlt)
plotActiveSubjects(StudyObjAlt)
The simulated HAZ values can be inspected using the plotHAZ
function.
plotHAZ(StudyObjAlt)
plotHAZTreatmentEff(StudyObjAlt)
The data can be used to update the posterior probability of the treatments to be better than the other treatments.
tmp <- getProbData(StudyObjAlt,strProb = "UnWeightedUpdateProbabilities",cohortAgeNames="6-18 months") kable(tmp %>% select(TreatmentName,Prob))
The alternative scenario is run 100 times to get statistics on the randomization probability updates.
iter <- 100 ncores <- 7 myMultStudAlt <- runMultiSim(StudyObjIniAlt,iter=iter,ncores=ncores)
Extract the probabilities of interest.
probDfUnweightedUpdateAlt <- getMultiProbList(myMultStudAlt[[1]],ncores=ncores, strProb="UnWeightedUpdateProbabilities", cohortAgeNames="6-18 months")
Summarise the end of treatment probabilities for plotting and tabulation.
sumDataAlt <- probDfUnweightedUpdateAlt %>% filter(RandStudyTime == max(RandStudyTime)) %>% group_by(TreatmentName,CohortAge) %>% summarise( Mean=mean(Prob), Low=quantile(Prob,p=0.025), High=quantile(Prob,p=0.975) )
Plot and tabulate the treatment probability statistics.
ggplot(sumDataAlt,aes(TreatmentName,Mean,color=TreatmentName)) + geom_point() + geom_errorbar(aes(ymin=Low,ymax=High),width=0.2) + facet_wrap(~CohortAge,scales = "free_x")
kable(sumDataAlt %>% select(TreatmentName,Mean,Low,High) %>% rename(Treatment =TreatmentName,"P0.025"=Low,"P0.975"=High),dig=2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.